﻿@using groupSecurity = FlashCards.WebApp.Security.GroupsSecurityProvider
@model FlashCards.WebApp.Models.GroupMembersModel
@{
    ViewBag.Title = "ViewGroupMembers";
    ViewBag.CanUserAddUsers = groupSecurity.CanUserAddUsers(User.Identity.Name, Model.Group.GroupId);
    ViewBag.CanUserSetRoles = groupSecurity.CanUserSetRoles(User.Identity.Name, Model.Group.GroupId);
}
<h2>
    ViewGroupMembers</h2>
@if (ViewBag.CanUserAddUsers)
{
    <p>
        @Html.ActionLink("Add friend to group", "AddFriendToGroup", new { groupId = Model.Group.GroupId })
    </p>
}
<table>
    <tr>
        <th>
            Name
        </th>
        <th>
            Surname
        </th>
        @if (ViewBag.CanUserSetRoles)
        { 
            <th>
            </th>
        }
        @if (ViewBag.CanUserAddUsers)
        {
            <th>
            </th>
        }
    </tr>
    @foreach (var item in Model.Members)
    {
        <tr>
            <td>
                @Html.DisplayFor(modelItem => item.Name)
            </td>
            <td>
                @Html.DisplayFor(modelItem => item.Surname)
            </td>
            @if (ViewBag.CanUserSetRoles)
            { 
                <td>
                    @if (item.UserName != Model.OwnerNick)
                    { 
                        @Html.ActionLink("Manage", "SetUserGroupRole", new { userId = item.UserId, groupId = Model.Group.GroupId })
                    }
                    else
                    {
                        <span>Owner</span>
                    }
                </td>
            }
            @if (ViewBag.CanUserAddUsers)
            { 
                <td>
                    @Html.ActionLink("Delete", "DeleteUserFromGroup", new { userId = item.UserId, groupId = Model.Group.GroupId })
                </td>
            }
        </tr>
    }
</table>
